<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<jsp:include page="../common/nav.jsp"></jsp:include>
<div class="wrapper wrapper-content animated fadeInRight">
	<jsp:include page="search.jsp"></jsp:include>
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
		        <div class="ibox-title">
		            <h4>采购申请列表</h4>
		            <div class="ibox-tools">
		                <button id="addButton" class="btn btn-success btn-sm" type="button" onclick="addData()"><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">发起采购申请</span></button>
		                <button id="searchButton" class="btn btn-default btn-sm btn-notcontrol" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
		            </div>
		        </div>
				<div class="ibox-content border-bottom" style="padding-bottom: 0;">
					<div class="table-responsive">
						<table class="table table-striped table-hover table-bordered border-top">
							<thead>
								<tr>
									<th width="5%">序号</th>
									<th>编号</th>
									<th>标题</th>
									<th>采购类型</th>
									<th>公司代码</th>
									<th>部门名称</th>
									<th>申请人</th>
                                    <th>申请时间</th>
									<th>期望交货时间</th>
									<th>采购原因</th>
									<th>状态</th>
									<th>附言</th>
									<th width="10%">操作</th>
								</tr>
							</thead>
							<tbody>
							    <c:forEach items="${requestScope.list}" var="data" varStatus="index">
									<tr>
										<td>${index.count}</td>
										<td>${data.code}</td>
										<td>${data.title}</td>
										<td>${requestScope.typeMap[data.type]}</td>
										<td>${data.companyCode.concat(' - '.concat(data.companyName))}</td>
										<td>${data.departmentName}</td>
										<td>${data.createUserName}</td>
                                        <td><fmt:formatDate value="${data.createTime}" pattern="yyyy-MM-dd"/></td>
										<td>${data.scheduledTime}</td>
										<td>${data.reason}</td>
										<td>${requestScope.statusMap[data.status]}</td>
										<td>${data.remark}</td>
										<td>
											<div class="btn-group">
												<button class="btn-white btn btn-xs btn-notcontrol" onclick="showData('${data.id}')"><i class="fa fa-eye"></i>&nbsp;查看</button>&nbsp;
												<c:if test="${data.status == '0'}">
													<button class="btn-white btn btn-xs btn-notcontrol" onclick="submitData('${data.id}')"><i class="fa fa-edit"></i>&nbsp;提交</button>&nbsp;
													<button class="btn-white btn btn-xs btn-notcontrol" onclick="editData('${data.id}')"><i class="fa fa-edit"></i>&nbsp;编辑</button>&nbsp;
													<button class="btn-white btn btn-xs" onclick="deleteData('${data.id}')"><i class="fa fa-trash"></i>&nbsp;删除</button>
												</c:if>
												<c:if test="${data.status == '1'}">
													<button class="btn-white btn btn-xs btn-notcontrol" onclick="recallData('${data.id}')"><i class="fa fa-edit"></i>&nbsp;撤回</button>&nbsp;
												</c:if>
											</div>
										</td>
									</tr>
								</c:forEach>
							</tbody>
							<tfoot>
							<jsp:include page="../common/pages.jsp"></jsp:include>
							</tfoot>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="js/listPage.js"></script>
<script>

	// 添加
	function addData(id) {
		window.location.href="web/purchasingRequisition/get";
	}

	// 编辑
	function editData(id) {
		window.location.href="web/purchasingRequisition/get?id=" + id;
	}

	// 提交
	function submitData(id) {
		redragonJS.confirm("确认提交申请？", function() {
			$.ajax({
				type : "get",
				url : "web/purchasingRequisition/submit?id=" + id,
				async : true,
				success: function (data) {
					if(data.code == 1) {
						redragonJS.alert("提交成功!");
						setTimeout(function(){
							window.location.href='web/purchasingRequisition/getPageList'
						},1000);
					} else {
						redragonJS.alert(data.msg);
					}
				}
			});
		});
	}

	// 撤回
	function recallData(id) {
		redragonJS.confirm("确认撤回申请？", function() {
			$.ajax({
				type : "get",
				url : "web/purchasingRequisition/recall?id=" + id,
				async : true,
				success: function (data) {
					if(data.code == 1) {
						redragonJS.alert("撤回成功!");
						setTimeout(function(){
							window.location.href='web/purchasingRequisition/getPageList'
						},1000);
					} else {
						redragonJS.alert(data.msg);
					}
				}
			});
		});
	}

	// 查看
	function showData(id) {
		window.location.href="web/purchasingRequisition/detail?id=" + id;
	}

	// 删除
	function deleteData(id) {
		redragonJS.confirm("确认删除数据？", function() {
			$.ajax({
				type : "get",
				url : "web/purchasingRequisition/del?id=" + id,
				async : true,
				success: function (data) {
					if(data.code == 1) {
						redragonJS.alert("删除成功!");
						setTimeout(function(){
							window.location.href='web/purchasingRequisition/getPageList'
						},1000);
					} else {
						redragonJS.alert(data.msg);
					}
				}
			});
		});
	}
</script>